package com.aaa.service.impl;

import com.aaa.common.domain.RenterInfo;
import com.aaa.common.domain.Selection;
import com.aaa.common.query.RenterInfoQuery;
import com.aaa.common.result.Result;
import com.aaa.mapper.RenterInfoMapper;
import com.aaa.service.RenterInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class RenterInfoServiceImpl extends ServiceImpl<RenterInfoMapper ,RenterInfo> implements RenterInfoService {

    @Autowired
    private RenterInfoMapper mapper;

    /**
     * 查询单位租户
     * @return
     */
    @Override
    public Result listUnitRenter(RenterInfoQuery renterQuery) {
        Page<RenterInfo> page = new Page<>(renterQuery.getPage(),renterQuery.getCount());
        Page<RenterInfo> listP = mapper.RenterListP(page, renterQuery.getName());
        return Result.success(listP);
    }

    /**
     * 查询个人租户
     * @return
     */
    @Override
    public Result listPersonalRenter(RenterInfoQuery renterQuery) {
        Page<RenterInfo> page = new Page<>(renterQuery.getPage(),renterQuery.getCount());
        Page<RenterInfo> list = mapper.PerRenterListP(page, renterQuery.getName());
        return Result.success(list);
    }

    @Override
    public Result listMark() {
        List<Selection> list = mapper.listSelect();
        return Result.success(list);
    }


    /**
     * 添加租户
     * @return
     */
    @Override
    public boolean addPersonalRenter(RenterInfo renterInfo){
        int i = mapper.insert(renterInfo);
        if (i>0){
            return true;
        }
        return false;
    }

    /**
     * 修改租户
     * @return
     */
    @Override
    public boolean updatePersonalRenter(RenterInfo renterInfo){
        int i = mapper.updateById(renterInfo);
        if (i>0){
            return true;
        }
        return false;
    }

    /**
     * 根据id查询租户
     * @param id
     * @return
     */
    @Override
    public Result listPersonalRenterById(Integer id) {
        RenterInfo renterInfo = mapper.queryById(id);
        return Result.success(renterInfo);
    }

    /**
     * 删除租户
     * @return
     */
    @Override
    public boolean deletePersonalRenter(String ids){
        Boolean delete = mapper.RenterUpdate(ids);
        if (delete==true){
            return true;
        }
        return false;
    }


}
